package cn._51doit.flink.day03;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class UnionDemo2 {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //spark
        DataStreamSource<String> lines1 = env.socketTextStream("localhost", 8888);

        SingleOutputStreamOperator<String> upper1 = lines1.map(String::toUpperCase).setParallelism(2);

        DataStreamSource<String> lines2 = env.socketTextStream("localhost", 9999);

        SingleOutputStreamOperator<String> upper2 = lines2.map(String::toUpperCase).setParallelism(3);

        //SingleOutputStreamOperator<Integer> nums = lines2.map(Integer::parseInt);

        //两个类型一样的DataStream才能union

        //lines1.union(nums)
        //DataStream<String> res = lines1.union(lines2);
        //DataStream<String> res = lines1.union(lines1);

        DataStream<String> res = upper1.union(upper2);
        res.print();

        env.execute();

    }
}
